package org.example.day02;

import java.util.Random;

/**
 * 第一章节1.10.3：优先级具有随机性
 *      线程优先级相差不大时，具有随机性
 */
public class MyThread9 extends Thread{
    @Override
    public void run() {
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 1000; i++) {
            Random random = new Random();
            random.nextInt();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("★ ★ ★ ★ use time = " + (endTime - beginTime));
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            MyThread9 m9 = new MyThread9();
            m9.setPriority(5);
            m9.start();
            MyThread10 m10 = new MyThread10();
            m10.setPriority(6);
            m10.start();
        }
    }
}

class MyThread10 extends Thread{
    @Override
    public void run() {
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 1000; i++) {
            Random random = new Random();
            random.nextInt();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("☆ ☆ ☆ ☆ use time = " + (endTime - beginTime));
    }
}
//①
//☆ ☆ ☆ ☆ use time = 1
//☆ ☆ ☆ ☆ use time = 13
//★ ★ ★ ★ use time = 3
//☆ ☆ ☆ ☆ use time = 4
//★ ★ ★ ★ use time = 5
//★ ★ ★ ★ use time = 16
//★ ★ ★ ★ use time = 2
//☆ ☆ ☆ ☆ use time = 0
//☆ ☆ ☆ ☆ use time = 0
//★ ★ ★ ★ use time = 0

//②
//☆ ☆ ☆ ☆ use time = 1
//★ ★ ★ ★ use time = 1
//☆ ☆ ☆ ☆ use time = 0
//★ ★ ★ ★ use time = 5
//★ ★ ★ ★ use time = 8
//☆ ☆ ☆ ☆ use time = 5
//☆ ☆ ☆ ☆ use time = 7
//★ ★ ★ ★ use time = 6
//☆ ☆ ☆ ☆ use time = 8
//★ ★ ★ ★ use time = 8